#ifndef _RING_BUFFER_H
#define _RING_BUFFER_H

#include <type.h>
#include <ds/mutex.h>

#define RBUF_DIRTY 1

typedef struct {
    size_t size;
    size_t pwrite; /* position of write */
    size_t pread; /* position of read */
    size_t free_len;
    u32 flags;
    mutex_t lock;
    void* data;
} rbuffer_t;

void rbuffer_init(rbuffer_t* buf, void* buffer, size_t size, u32 flags);

size_t rbuffer_write(rbuffer_t* fbuf, void* data, size_t count);

size_t rbuffer_read(rbuffer_t* fbuf, void* buf, size_t count);

size_t rbuffer_readone_async(rbuffer_t* fbuf, char* data);

void rbuffer_set_wptr(rbuffer_t* fbuf, size_t wptr);

void rbuffer_set_rptr(rbuffer_t* fbuf, size_t rptr);

void rbuffer_clear(rbuffer_t* fbuf);

#endif // _RING_BUFFER_H